/* Copyright (c) 2004-2022 peigen.info. All rights reserved. */

package com.gitee.peigenlpy.actable.example.repository.entity;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import com.gitee.peigenlpy.actable.example.repository.entity.enums.YesOrNo;
import com.google.common.collect.Lists;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;

import java.util.List;


/**
 * <b>(CustomerPermission)</b>
 * 客户权限
 * 这里以json的方式存储,可随意增加
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/7/28
 */
@SuppressWarnings("unused")
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@Accessors(chain = true)
public class CustomerPermission {
    /** 可登录 */
    @Builder.Default
    YesOrNo login              = YesOrNo.N;
    /** 可修改登录密码 */
    @Builder.Default
    YesOrNo editLoginPassword  = YesOrNo.N;
    /** 可支付 */
    @Builder.Default
    YesOrNo pay                = YesOrNo.N;
    /** 可修改交易密码 */
    @Builder.Default
    YesOrNo editPayPassword    = YesOrNo.N;
    /** 是否发送30天证件过期提醒 */
    @Builder.Default
    YesOrNo sendThirtyReminder = YesOrNo.Y;
    /** 是否发送90天证件过期提醒 */
    @Builder.Default
    YesOrNo sendNinetyReminder = YesOrNo.Y;

    public YesOrNo isSendThirtyReminder() {
        return sendNinetyReminder;
    }

    public YesOrNo isSendNinetyReminder() {
        return sendNinetyReminder;
    }

    public YesOrNo isLogin() {
        return login;
    }

    public YesOrNo isEditLoginPassword() {
        return editLoginPassword;
    }

    public YesOrNo isPay() {
        return login;
    }

    public YesOrNo idEditPayPassword() {
        return editPayPassword;
    }

    public void check() {
        Assert.isTrue(ObjectUtil.isAllNotEmpty(login, pay, sendThirtyReminder, sendNinetyReminder), "权限不得为空!");
    }

    public boolean permissionAllClose() {
        List<YesOrNo> allPermission = Lists.newArrayList(login, editLoginPassword, pay, editPayPassword, sendThirtyReminder, sendNinetyReminder);
        return allPermission.stream().noneMatch(p -> p == YesOrNo.Y);
    }

}
